//
//  SDCommon.m
//  for_test
//
//  Created by Carlson Lee on 2017/4/1.
//  Copyright © 2017年 Carlson Lee. All rights reserved.
//

#import "SDCommon.h"


@implementation SDCommon

NSString* fontName(FONT_TYPE tp){
    switch (tp) {
        case FONT_TYPE_REGULAR:{
            return @"PingFangSC-Regular";
        }
            break;
        case FONT_TYPE_SEMIBOLD:{
            return @"PingFangSC-Semibold";
        }
            break;
        default:
            break;
    }
}

UIFont* SDFont(CGFloat size, FONT_TYPE tp){
    UIFont* font = [UIFont fontWithName:fontName(tp) size:size*ScaleX];
    if(!font){
        font = [UIFont systemFontOfSize:size*ScaleX];
    }
    return font;
}

CGSize SDSize(NSString* str, UIFont* font, CGSize size){
    if(!str || !str.length)return CGSizeZero;
    if(!size.width || !size.height){
        return [str sizeWithAttributes:@{NSFontAttributeName:font}];
    }
    return [str boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil].size;
}

@end
